function gvec = lmj_counterfactual_plot(smooth_st, smooth_counter, countmat, counter_countmat, ...
    state_rep, state_names, shock_rep, shock_names, sample, flag_color)
cucd = pwd; 
respath = pwd; 

flag_color = 1; 
widthvec=[2.5 2]; 
T = size(smooth_st, 1); 

pos_statesel = cellposition(state_rep, state_names); 
pos_shocksel = cellposition(shock_rep, shock_names); 


ns_sel = length(state_rep); 
nx_sel = length(shock_rep); 
nc = 2; 
nr = ceil(nx_sel/2) + 1; 

for ii = 1:ns_sel;
    ghand = figure;
    stapos = pos_statesel(ii);
    for jj = 1:(1+nx_sel);
        % first subplot
        if jj == 1;
            subplot(nr, 1, 1); hold on;
            hand1 = plot(sample, smooth_st(:, stapos), 'LineWidth',widthvec(1));
            hand2 = plot(sample, smooth_counter(:, stapos), '--','LineWidth',widthvec(2));
            title('smoothed state', 'FontSize',11)%,'FontName','Helvetica')
        else
            % remaining subplots
            shopos = pos_shocksel(jj-1);
            subplot(nr, nc, jj+1)
            hand1 = plot(sample, countmat(:, stapos, shopos), 'LineWidth',widthvec(1)); hold on
            hand2 = plot(sample, counter_countmat(:, stapos, shopos), '--','LineWidth',widthvec(2));
            title(shock_names{shopos}, 'FontSize',11)%,'FontName','Helvetica')
        end
        if flag_color==1
            set(hand1,'Color','b')
            set(hand2,'Color','r','MarkerSize',2);  hold off;
        else
            veclight=[0.55 0.55 0.55];
            set(hand1,'Color',[0.0 0.0 0.0],'LineWidth',widthvec(1));
            set(hand2,'Color',veclight,'LineStyle','--','MarkerSize',1,'LineWidth',widthvec(2));
        end
        if T <= 24
            set(gca,'Xtick',sample(1):1:sample(end))
        elseif T > 24 && T <= 40
            set(gca,'Xtick',sample(1):2:sample(end))
        else
            set(gca,'Xtick',sample(1):4:sample(end))
        end
    end
    titlehand=suptitle([state_rep{ii},': decomposition across shocks']); 
    set(titlehand,'FontSize',14)%,'FontName','Helvetica');
    set(ghand,'PaperPosition',[0.75 0.5 7.5 10])
    gvec(ii) = ghand;
end
cd(respath); 
for ii=1:ns_sel;
    print(gvec(ii),'-dpsc','decomp_accross_shock','-append'); 
end
cd(cucd); 



end